<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改学生信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=basePath%>/layui/css/layui.css" media="all">
  <script src="<%=basePath%>/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<form class="layui-form" id ="form">
	<div class="layui-form-item" style="margin-top:50px;">
		<input class="layui-input" id="stuId" style="display:none">
	    <div class="layui-form-item">
		    <label class="layui-form-label">学号：</label>
		    <div class="layui-input-inline">
			    <input class="layui-input" style="width:300px;" type = "text" id="sno" lay-verify="required" lay-reqtext="账号是必填项！" disabled="disabled" >
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">姓名：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sname" lay-verify="required" lay-reqtext="用户名是必填项！">
			</div>
		</div>
		<div class="layui-form-item">
		<!-- layui 与 jsp 冲突  单选框或起不了  -->
		    <label class="layui-form-label">性别：</label>
		    <div class="layui-input-inline">
		    <!-- <input  class="layui-input" style="width:300px;" type = "text" id="sex"> --> 
			  <input type="radio" name="sex" lay-filter="erweima" value="男" title="男" checked>
			   <input type="radio" name="sex" lay-filter="erweima" value="女" title="女" > 
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">密码：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sPassword">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">系部：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sDepartment">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">班级：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sClass">
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">邮件：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="email">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">手机：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sPhone">
			</div>
		</div>
	    <div class="layui-form-item" style="margin-left:180px;margin-top:50px;">
			<button type="button" class="layui-btn" onclick="edit();">保存</button>
			<button type="button" class="layui-btn" onclick="back();">返回</button>
		</div>
 	 </div>
</form>
</body>


<script src="<%=basePath%>/js/vue.min.js"></script>
<script src="<%=basePath%>/layui/layui.js" charset="utf-8"></script>
<script>
layui.use('form',function(){
	var form = layui.form;
	$('#stuId').val(localStorage.getItem("stuId"));
	$('#sno').val(localStorage.getItem("sno"));
	$('#sname').val(localStorage.getItem("sname"));
	//$('#sex').val(localStorage.getItem("sex"));
	$("input[type='radio']:checked").val(localStorage.getItem("sex"));
	$('#sPassword').val(localStorage.getItem("sPassword"));
	$('#sDepartment').val(localStorage.getItem("sDepartment"));
	$('#sClass').val(localStorage.getItem("sClass"));
	$('#email').val(localStorage.getItem("email"));
	$('#sPhone').val(localStorage.getItem("sPhone"));
	//全部更新 解决单选框不渲染
	form.render();
});


function edit(){
	var param = new Object();
	param.stuId = $('#stuId').val();
	param.sno  = $('#sno').val();
	param.sname = $('#sname').val();
	param.sex = $('input[name="sex"]:checked').val();
	param.sPassword = $('#sPassword').val();
	param.sDepartment = $('#sDepartment').val();
	param.sClass = $('#sClass').val();
	param.email = $('#email').val();
	param.sPhone = $('#sPhone').val();
	console.log("send message:"+JSON.stringify(param));
	$.ajax({
		type:"GET",
		url:"/bysjxksys/admin/edit_stu",
		dataType:"json",
		//contentType:"application/json",
        data:param,
		success: function(data){
			if(data.code==1){
				alert(data.msg);
			}else{
				alert("数据更新成功！");
				parent.location.reload();				
			}
		},
		error: function(data, type, err){
			console.log(type);
			console.log(err);
		}
	});
};

function back(){
	//当你在iframe页面关闭自身时
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
    window.location.reload();
}


</script>
</html>